package com.example.springbean.pkg;


import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Publisher {

    @Autowired
    AmqpTemplate amqpTemplate;

    public void sendHeader(Object message) {
        String msg = "消息";

        MessageProperties mp = new MessageProperties();
        mp.setHeader("header1", "value1");
        mp.setHeader("header2", "value2");
        // 与 配置中的map完全匹配，因为那边是 whereAll()方法
        Message message1 = new Message(msg.getBytes(), mp);
        amqpTemplate.convertAndSend("header.exchange", "", message1);
        // 可以匹配到 topic.# and topic.key1
    }
}
